package com.ysx.oa.resume.controller;

import com.ysx.oa.resume.Bean.QuestionBean;
import com.ysx.oa.resume.service.QuestionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

/**
 * @author 黄德标
 * @date 2021/11/23 22:13
 */
@RestController
@RequestMapping("/question")
@CrossOrigin
public class QuestionController {

    @Autowired
    private QuestionService questionService;

    /**
     * 方法描述: 【学生】 通过QuestionBean对象的resumeId属性 添加一个面试问题
     * URL: localhost:8080/kaoqin/question/addQuestionByResumeId
     * {
     *     "resumeId"  : 1111,
     *     "question": "测试面试问题",
     *     "studentAnswer":"测试学生回答"
     * }
     * @author: 黄德标
     * @date: 2021/11/23 22:20
     * @param: QuestionBean对象
     */
    @RequestMapping(value = "/addQuestionByResumeId",method = RequestMethod.POST)
    public Map<String,Object> addQuestionByResumeId(@RequestBody QuestionBean questionBean)
    {
        Map<String,Object> map = new HashMap<>();

        questionService.addQuestion(questionBean);

        map.put("code",200);
        map.put("message","success");
        map.put("data","添加成功");
        return map;
    }

    /**
     * 方法描述: 【学生】 根据 QuestionId 删除学生 面试记录中的问题
     * URL: localhost:8080/kaoqin/question/deleteQuestionByQuestionId
     * {
     *     "questionId" : 28,
     * }
     * @author: 黄德标
     * @date: 2021/11/25 14:37
     * @param: [java.lang.Integer]
     */
    @RequestMapping(value = "/deleteQuestionByQuestionId",method = RequestMethod.POST)
    public Map<String,Object> deleteQuestionByQuestionId(@RequestBody Integer questionId){
        Map<String,Object> map = new HashMap<>();
        questionService.deleteQuestionByQuestionId(questionId);
        map.put("code",200);
        map.put("message","success");
        map.put("data","删除成功");
        return map;
    }

    /**
     * 方法描述: 【学生】 根据 QuestionBean 更新学生 面试记录中的问题
     * URL: localhost:8080/kaoqin/question/updateQuestion
     * {
     *     "id" : 22,
     *     "question": "测试面试问题",
     *     "studentAnswer":"测试学生回答"
     * }
     * @author: 黄德标
     * @date: 2021/11/25 14:37
     * @param: [java.lang.Integer]
     */
    @RequestMapping(value = "/updateQuestion",method = RequestMethod.POST)
    public Map<String,Object> updateQuestion(@RequestBody
                                             QuestionBean questionBean,
                                             HttpServletRequest request,
                                             HttpServletResponse response)
    {
        Map<String,Object> map = new HashMap<>();

        questionService.updateQuestion(questionBean);
        map.put("code",200);
        map.put("message","success");
        map.put("data","修改成功");
        return map;
    }

    /**
     * 方法描述: 【学生】 通过resumeId 查找 该面试记录 的所有问题
     * URL: localhost:8080/kaoqin/question/selectQuestionByResumeId
     * @author: 黄德标
     * @date: 2021/11/24 21:11
     * @param: [java.lang.Integer]
     * @return: java.util.Map<java.lang.String,java.lang.Object>
     */
    @RequestMapping(value = "/selectQuestionByResumeId",method = RequestMethod.GET)
    public Map<String,Object> selectQuestionByResumeId(Integer resumeId){
        Map<String,Object> map = new HashMap<>();
        ArrayList<QuestionBean> questionList
                = questionService.selectQuestionBeanByResumeId(resumeId);
        map.put("code",200);
        map.put("message","success");
        map.put("data",questionList);
        return map;
    }

    /**
     * 方法描述: 【学生】 查找 自己 所有面试 的所有问题
     * URL: localhost:8080/kaoqin/question/selectQuestionByStudentId
     * @author: 黄德标
     * @date: 2021/11/24 21:11
     * @param: [java.lang.Integer]
     * @return: java.util.Map<java.lang.String,java.lang.Object>
     */
    @RequestMapping(value = "/selectQuestionByStudentId",method = RequestMethod.GET)
    public Map<String,Object> selectQuestionByStudentId(HttpServletRequest request,
                                                        HttpServletResponse response){
        Map<String,Object> map = new HashMap<>();

        HttpSession session = request.getSession();
        Integer userId =(Integer) session.getAttribute("userId");

        ArrayList<QuestionBean> questionBeanArrayList
                = questionService.selectQuestionBeanByStudentId(userId);

        map.put("code",200);
        map.put("message","success");
        map.put("data",questionBeanArrayList);
        return map;
    }

//======================================  老师调用的Controller ======================================

    /**
     * 方法描述: 【老师】 查找 自己本班 所有学生 面试的问答
     * URL: localhost:8080/kaoqin/question/findQuestionByTeacherId?teacherId=100007
     * @author: 黄德标
     * @date: 2021/11/25 17:02
     * @param: resumeId
     */
    @RequestMapping(value = "/findQuestionByTeacherId",method = RequestMethod.GET)
    public Map<String,Object> findQuestionByTeacherId(Integer teacherId){
        Map<String,Object> map = new HashMap<>();



        map.put("code",200);
        map.put("message","success");
        map.put("data",null);
        return map;
    }


    /**
     * 方法描述:  查找 所有学生 面试的问答
     * URL: http://localhost:8080/kaoqin/question/findAllQuestion
     * @author: 黄德标
     * @date: 2021/11/25 17:02
     * @param: resumeId
     */
    @RequestMapping(value = "/findAllQuestion",method = RequestMethod.GET)
    public Map<String,Object> findAllQuestion(){
        Map<String,Object> map = new HashMap<>();

        ArrayList<QuestionBean> questionBeanArrayList
                = questionService.selectAll();

        map.put("code",200);
        map.put("message","success");
        map.put("data",questionBeanArrayList);
        return map;
    }



}